package to;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "tbl_funcionario")
public class Funcionario implements Serializable {
	private static final long serialVersionUID = -7483125972662800382L;

	@Id
	@GeneratedValue
	private Integer codigo;

	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name="id_pessoa", nullable = false)
	private Pessoa pessoa;

	@ManyToOne
	@JoinColumn(name = "id_cargo")
	private Cargo cargo;

	@ManyToOne
	@JoinColumn(name = "id_laboratorio", nullable = true)
	private Laboratorio laboratorio;

	@Temporal(TemporalType.DATE)
	private Date dataAdmissao;

	@Temporal(TemporalType.DATE)
	private Date dataDemissao;

	@Column(length = 45)
	private String crea;

	public Integer getCodigo() {
		return codigo;
	}

	public void setCodigo(Integer codigo) {
		this.codigo = codigo;
	}

	public Pessoa getPessoa() {
		return pessoa;
	}

	public void setPessoa(Pessoa pessoa) {
		this.pessoa = pessoa;
	}

	public Cargo getCargo() {
		return cargo;
	}

	public void setCargo(Cargo cargo) {
		this.cargo = cargo;
	}

	public Laboratorio getLaboratorio() {
		return laboratorio;
	}

	public void setLaboratorio(Laboratorio laboratorio) {
		this.laboratorio = laboratorio;
	}

	public Date getDataAdmissao() {
		return dataAdmissao;
	}

	public void setDataAdmissao(Date dataAdmissao) {
		this.dataAdmissao = dataAdmissao;
	}

	public Date getDataDemissao() {
		return dataDemissao;
	}

	public void setDataDemissao(Date dataDemissao) {
		this.dataDemissao = dataDemissao;
	}

	public String getCrea() {
		return crea;
	}
	
	public void setCrea(String crea) {
		this.crea = crea;
	}

	public String getDataAdmissaoFormatada() {
		return new SimpleDateFormat("dd/MM/yyyyy").format(dataAdmissao);
	}
	public String getDataAdmissaoDemissao() {
		return new SimpleDateFormat("dd/MM/yyyyy").format(dataDemissao);
	}
}
